/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.model;

/**
 * @author Administrador.
 */
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.db.SqlManager;
import com.exception.DataException;
import com.javabeans.DiaSemana;

public class AdminDiaSemana implements DiaSemanaManager{
    private Connection c;

    public AdminDiaSemana(Connection c){
        this.c = c;
    }
    
    @Override
    public List<DiaSemana> getDias() throws DataException{
        List<DiaSemana> dias = new ArrayList<DiaSemana>();
        ResultSet rs = null;
        PreparedStatement preSt = null;
        try{
            String query = "SELECT IDDIA_SEMANA, NOMBRE FROM DIA_SEMANA ORDER BY ORDEN";            
            preSt = c.prepareStatement(query);
            rs = preSt.executeQuery();
            while(rs.next()){
                DiaSemana ds = new DiaSemana();
                ds.setIdDiaSemana(rs.getInt("IDDIA_SEMANA"));
                ds.setNombre(rs.getString("NOMBRE"));
                dias.add(ds);
            }
            
        }catch(SQLException sql){
            throw new DataException("Error! AdminDiaSemana -> getDias() sql = "+sql.getMessage());
        }finally{
            SqlManager.closeRs(rs);
            SqlManager.closePreSt(preSt);
        }
        return dias;
    }
    
    @Override
    public List<DiaSemana> getDiasHorario() throws DataException{
        List<DiaSemana> dias = new ArrayList<DiaSemana>();
        ResultSet rs = null;
        PreparedStatement preSt = null;
        try{
            String query = "SELECT IDDIA_SEMANA, NOMBRE FROM DIA_SEMANA WHERE HORARIO = 1 ORDER BY ORDEN";            
            preSt = c.prepareStatement(query);
            rs = preSt.executeQuery();
            while(rs.next()){
                DiaSemana ds = new DiaSemana();
                ds.setIdDiaSemana(rs.getInt("IDDIA_SEMANA"));
                ds.setNombre(rs.getString("NOMBRE"));
                dias.add(ds);
            }
            
        }catch(SQLException sql){
            throw new DataException("Error! AdminDiaSemana -> getDiasHorario() sql = "+sql.getMessage());
        }finally{
            SqlManager.closeRs(rs);
            SqlManager.closePreSt(preSt);
        }
        return dias;
    }
}
